#include "WarGameLib.h"



wgTimer::wgTimer()
{
	DEVMODE devMode;
	if(EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &devMode))
		refreshRate = devMode.dmDisplayFrequency;
	else
	{
		cout << "Unable to retrieve display settings. Using 60Hz." << endl;
		refreshRate = 60;
	}

	Update();
}

void wgTimer::WaitVSync()
{
	clock_t ticks;
	do
	{
		ticks = clock();
	}while( double(ticks - last_tick) < 1000.0 / (double)refreshRate);
}


long wgTimer::Update()
{
	clock_t now = clock();
	clock_t diff = now - last_tick;
	last_tick = now;
	return diff;
}

long wgTimer::getTicks()
{
	return clock();
}
float wgTimer::getSeconds(long ticks)
{
	return ticks / (float)(CLOCKS_PER_SEC);
}